package com.wsoft.hr.pm.controller;

import com.wsoft.hr.pm.query.target.group.TargetGroupInsertQuery;
import com.wsoft.hr.pm.query.target.group.TargetGroupTreeQuery;
import com.wsoft.hr.pm.query.target.group.TargetGroupUpdateQuery;
import com.wsoft.hr.pm.service.IHrPmTargetGroupService;
import com.wsoft.hr.pm.vo.target.group.TargetGroupTreeVO;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 指标分组 前端控制器
 * @author Z001
 * @since 2025年02月17日 15:07:36
 */
@RestController
@Tag(name = "指标分组")
@RequestMapping("/hr/pm/group")
public class HrPmTargetGroupController {

    @Resource
    private IHrPmTargetGroupService targetGroupService;

    @Operation(summary = "新增分组", description = "新增分组")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid TargetGroupInsertQuery query) {
        boolean b = targetGroupService.insertGroup(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "编辑分组", description = "编辑分组")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid TargetGroupUpdateQuery query) {
        boolean b = targetGroupService.updateGroup(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "分组tree", description = "分组tree")
    @PostMapping("/tree")
    public ResponseResult tree(@RequestBody TargetGroupTreeQuery query) {
        List<TargetGroupTreeVO> list = targetGroupService.tree(query);
        return ResponseResult.success(list);
    }

    @Operation(summary = "分组详情", description = "分组详情")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(targetGroupService.get(id));
    }


    @Operation(summary = "删除分组", description = "删除分组")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = targetGroupService.delete(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
}
